<script>
	import {
		mapMutations
	} from 'vuex'
	import {
		joinOrOutAppApi
	} from 'common/API/loginApi.js'
	export default {
		methods: {
			...mapMutations('user', ['MusetProjectCode']),
		},
		onLaunch: async function(option) {

			//版本更新开始
			if (wx.canIUse('getUpdateManager')) {
				const updateManager = wx.getUpdateManager()
				updateManager.onCheckForUpdate(function(res) {
					console.log('onCheckForUpdate====', res)
					// 请求完新版本信息的回调
					if (res.hasUpdate) {
						console.log('res.hasUpdate====')
						updateManager.onUpdateReady(function() {
							wx.showModal({
								title: '更新提示',
								content: '新版本已经准备好，是否重启应用？',
								success: function(res) {
									console.log('success====', res)
									// res: {errMsg: "showModal: ok", cancel: false, confirm: true}
									if (res.confirm) {
										// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
										updateManager.applyUpdate()
									}
								}
							})
						})
						updateManager.onUpdateFailed(function() {
							// 新的版本下载失败
							wx.showModal({
								title: '已经有新版本了哟~',
								content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~'
							})
						})
					}
				})
			}
			//版本更新结束
			console.log(option.referrerInfo.extraData, '营销小程序参数')
			if (option.referrerInfo.extraData) {
				uni.setStorageSync('goodInfo', JSON.stringify(option.referrerInfo.extraData))
			}
			if (!uni.getStorageSync('ylProjectCode')) {
				const {
					data: res
				} = await uni.$http.post(
					`/api/miniApp/config/queryByAppId/${uni.getAccountInfoSync().miniProgram.appId}`)
				this.MusetProjectCode(res.data)
			}
			const res = await joinOrOutAppApi(1)
			console.log('进入小程序埋点',res)
			
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: async function() {
			console.log('App Hide')
			const res = await joinOrOutAppApi(2)
			console.log('退出小程序埋点',res)
		}
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	/*每个页面公共css */
	@import '@/uni_modules/uni-scss/index.scss';
	/* #ifndef APP-NVUE */
	@import '@/static/customicons.css';
	@import '@/static/css/common.scss';
	@font-face {
		font-family: "ziyouwenyihei";
		src: url('https://bzhl-dev1.oss-cn-chengdu.aliyuncs.com/bzhl/miniapp/ziyouwenyihei.ttf');
	}
	
	@font-face {
		font-family: "ysbthzt";
		src: url('https://bzhl-dev1.oss-cn-chengdu.aliyuncs.com/bzhl/miniapp/ysbthzt.ttf');
	}


	// 设置整个项目的背景色
	page {
		// background-color: #f5f5f5;
	}

	uni-page-body,
	html,
	body {
		// height: 100%;
	}

	/* #endif */
	.example-info {
		font-size: 14px;
		color: #333;
		padding: 10px;
	}
</style>